package com.weirong.smartvault.backservice.util.table;

import com.weirong.smartvault.backservice.entity_model.*;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kfeb4
 * Date: 2017/12/29
 * Time: 11:02
 * 核账表的表格生成器
 */
public class ConfirmTable {
    public static Table buildTable(ConfirmLogModel logModel) throws NoSuchMethodException, NoSuchFieldException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Table table = new Table(9);
        Collection<MoneyLogCollectionModel<MoneyLogModel>> t = logModel.getRequests();
        List<MoneyLogCollectionModel<MoneyLogModel>> money = new ArrayList<>(t);
        List<ConfirmDetailLogModel> detailLogModels = logModel.getConfirmDetailLogModel();//包
        Integer max = money.size() > detailLogModels.size() ? money.size() : detailLogModels.size();
        for (int i = 0; i < max; i++) {
            CommandTable.setRequests(table, money, i);
            if(i<detailLogModels.size()){
                //填写包信息
                ConfirmDetailLogModel confirmDetail = detailLogModels.get(i);
                List<MoneyLogModel> deliverys = confirmDetail.getDeliveryDetail();
                table.setOne(3,"包"+(i+1),deliverys.size());
                for(MoneyLogModel moneyLogModel:deliverys){
                    table.setOne(4,moneyLogModel.getCurrencyName(),1);
                    table.setOne(5, String.valueOf(moneyLogModel.getDenominationType()),1);
                    table.setOne(6, String.valueOf(moneyLogModel.getAmount()),1);
                }
                table.setOne(7,confirmDetail.getConfirmResult(),deliverys.size(),deliverys.size(), String.valueOf(confirmDetail.getId()));
                table.setOne(8,confirmDetail.getFailReson(),deliverys.size(),deliverys.size());
            }
        }
        table.freeze();
        return table;
    }
}
